//
//  BadgeBtn.swift
//  MikerShop
//
//  Created by eme on 2017/2/16.
//  Copyright © 2017年 eme. All rights reserved.
//


import Foundation
import SnapKit
import RxSwift
import UtilCore
import RickonCore

class BadgeBtn: UIButton {
    
    ///显示数量
    var badgeCount:Int = 0{
        didSet{
            if badgeCount == 0 {
                self.badge_Lb.isHidden = true
            }else{
                self.badge_Lb.isHidden = false
                if badgeCount > 9 {
                    self.badge_Lb.text = "9+"
                }else{
                    self.badge_Lb.text = "\(badgeCount)"
                }
            }
        }
    }
    let badge_Lb = UILabel()
    override func awakeFromNib() {
        setupSubviews()
    }
    func setupSubviews() {
        badge_Lb.textAlignment = .center
        badge_Lb.textColor = UIColor.white
        badge_Lb.font = UIFont(name: Theme.fontName, size: 10)
        badge_Lb.text = "\(self.badgeCount)"
        badge_Lb.backgroundColor = UIColor(r: 209, g: 57, b: 61)
        self.addSubview(badge_Lb)
        var margn:CGFloat = 1
        switch Device.size {
        case .Screen3_5Inch:
            margn = 1
        case .Screen4Inch:
           margn = 1
        case .Screen4_7Inch:
            margn = 2
        case .Screen5_5Inch:
            margn = 3
        case .Screen7_9Inch:
            margn = 3
        case .Screen9_7Inch:
            margn = 3
        case .Screen12_9Inch:
            margn = 3
        default:
            margn = 3
        }
        self.badge_Lb.snp.makeConstraints{ make in
            make.trailing.equalTo(-margn)
            make.top.equalTo(margn)
            make.height.equalTo(18)
            make.width.equalTo(18)
        }
        badge_Lb.layer.masksToBounds = true
        badge_Lb.layer.cornerRadius = 9
        
    }


}

